from PIL import Image, ImageEnhance

# read an image and show
img = Image.open("images/lena_contrast.png")
img.show()

# write and save an image
img.save("images/temp.png")

# crop an image
dim = (100, 100, 300, 300)
crop_img = img.crop(dim)
# crop_img.show()

# get the color value of the pixel
print("the pixel values of this image are", img.getpixel((100, 100)))

# put the color value of the pixel
img.putpixel((100, 100), (20, 0, 30))
# print("the pixel values of this image are", img.getpixel((100, 100)))

# convert a color image to grayscale
grayscale_img = img.convert("L")
# grayscale_img.show()

# resize an image
resize_img = img.resize((100, 100))
# resize_img.show()

# rotate an image
rotate_img = img.rotate(45)
# rotate_img.show()

# change brightness of an image
enhancer = ImageEnhance.Brightness(img).enhance(2)
# enhancer.show()

# change contrast of an image
enhancer2 = ImageEnhance.Contrast(img).enhance(2)
# enhancer2.show()
